function PAA_DM = PAA(datafile,segwidth)
% load syndata10_16.mat

% load(matfile)

origdata=load(datafile);



data=origdata;

w=size(origdata,2)/segwidth;

break_points=[-1.5341205 -1.1503494 -0.8871466 -0.6744898 -0.4887764 -0.3186394 -0.1573107  0.0000000  0.1573107  0.3186394 0.4887764  0.6744898  0.8871466  1.1503494  1.5341205];

% break points distance matrix  
for i=1:size(break_points,2)+1
    for j=1:size(break_points,2)+1
        if abs(i-j)<=1
            BP_DM(i,j) = 0;
        else
            BP_DM(i,j)=break_points(max(i,j)-1)-break_points(min(i,j));
        end
    end
end
        


[num_ts,lenth_ts]=size(data);
seg_width=lenth_ts/w;

for i=1:num_ts
    data_PAA(i,:) = encode_PAA(seg_width,data(i,:));
end

PAA_DM=zeros(num_ts);
for i=1:num_ts
    for j=i+1:num_ts 
        PAA_DM(i,j)= 0;
        for k=1:w
            PAA_DM(i,j)= PAA_DM(i,j)+BP_DM(data_PAA(i,k),data_PAA(j,k))^2;
        end
        PAA_DM(i,j)=sqrt(seg_width*PAA_DM(i,j));
    end
end

PAA_DM=PAA_DM+PAA_DM';

% ED=dist(origdata');
% ratio=ones(600);
% 
% for i=1:600
% for j=i+1:600
% ratio(i,j)=PAA_DM(i,j)/ED(i,j);
% end
% end


    